$(function() {
    // 商品店铺
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getgsshop",
        dataType: "json",
        success: function(res) {
            console.log(res.result);
            var html = template("shopNameTmp", res);
            $(".shopName").html(html);
            $('.name i').html($(".shopName li:nth-child(1)").html());
            $('.name input').val($(".shopName li:nth-child(1)").attr("data-nameId"));
            getProNew();
        }
    });
    // 商品区域
    $.ajax({
        type: "get",
        url: "http://193.112.55.79:9090/api/getgsshoparea",
        dataType: "json",
        success: function(res) {
            console.log(res);
            var html = template("shopAreaTmp", res);
            $(".shopArea").html(html);
            $('.area i').html($(".shopArea li:nth-child(1)").html());
            $('.area input').val($(".shopArea li:nth-child(1)").attr("data-areaId"));
            getProNew();
        }
    });

    // 点击按钮，显示选项栏
    var index;
    $('.screen_button div').on('click', function() {
        //当前点击的li标签的索引
        index = $(this).index();
        // console.log(index);
        //当前的选项栏显示，其余的隐藏
        $('.content ul').eq(index).toggle().siblings().hide();
    })
    $('.content ul').on('click', 'li', function() {
        if (index == 0) {
            $('.name i').html($(this).html());
            $('.name input').val($(this).attr("data-nameId"));
        } else if (index == 1) {
            $('.area i').html($(this).html());
            $('.area input').val($(this).attr("data-areaId"));
        } else if (index == 2) {
            $('.spri i').html($(this).html());
        }
        $('.content ul').hide();
    })

    $('.sx_search').on('click', function() {
        getProNew();
    })



    function getProNew() {
        var data = $('#form').serialize();
        //console.log(data);
        $.ajax({
            type: "get",
            url: "http://193.112.55.79:9090/api/getgsproduct",
            data: data,
            dataType: "json",
            success: function(res) {
                console.log(res);
                var html1 = template("shopListTmp", res);
                $('.comm_list ul').html(html1);
            }
        });
    }
})